using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Windows.Forms;

using Styx.Common;
using Styx.CommonBot.Frames;
using Styx.CommonBot;
using Styx.Pathing;
using Styx.Plugins;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using Styx;



namespace GB2Fix
{
    public class GB2Fix : HBPlugin
    {

        public override string Name { get { return "GB2Fix by arczi19"; } }
        public override string Author { get { return "arczi19"; } }
        public override Version Version { get { return new Version(1, 0, 0, 6); } }

        private double CombatTimeout = 660;
        private Stopwatch combatTimer = new Stopwatch();


        public void SellItem(string Itemname)
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                if (item.Name == Itemname)
                {
                    Logging.Write("Selling Item {0}", item.Name);
                    item.UseContainerItem();
                }
            }
        }

        public override void Pulse()
        {


            if (StyxWoW.Me.Mounted && !StyxWoW.Me.HasAura("Resurrection Sickness"))
            {
                combatTimer.Start();
            }
            else
            {
                combatTimer.Stop();
                combatTimer.Reset();
            }

            if (combatTimer.Elapsed.TotalSeconds > CombatTimeout)
            {
                Mount.Dismount();
                combatTimer.Reset();
            }
            if (Styx.CommonBot.Frames.MerchantFrame.Instance.IsVisible)
            {
                SellItem("Life Spirit");
                SellItem("Water Spirit");
            }
        }


    }
}